$(function(){
    //获取url参数
	function GetQueryString(name){
		var reg = new RegExp("(^|&)"+name+"=([^&]*)(&|$)");
		var r = window.location.search.substr(1).match(reg);
		if(r!=null)return unescape(r[2]); return null;
    }

    exchangeStudent=function(table){
        exchange_student=$("#student_id").val();
        exchange=new Object();
        exchange.exchange_student=exchange_student;
        exchange.student=$(table).parents("tr").find(".student_id").html();
        exchangeJSON=JSON.stringify(exchange);
        //alert(exchangeJSON);
        gender=$("#gender").val();
        gender_t=$(table).parents("tr").find(".gender").html();
        if(gender==gender_t){
            layer.confirm('确定调换？',{btn:['确定','取消']},function(){
                $.post("/php/student-dormitory-exchanging.php",{action:1,data:exchangeJSON},
                function(result){
                    
                    resultObj=JSON.parse(result);
                    switch(resultObj.code){
                        case '2001':
                        layer.msg(resultObj.message,{icon:1,btn:['确定']},function(){
                            location.replace(location.href);
                        });
                        break;
                        case '2004':layer.msg(resultObj.message);break;
                        default:break;
                    }
                });
            });
            
        }else{
            layer.msg('性别不匹配');
        }
        
    }

    $("select").change(function(){
        var id=$(this).attr("id");
        switch(id){
            case "jump_page":
                var allocate=GetQueryString('student_id');
                student_id=student_id==null?0:student_id;
        
                var grade=GetQueryString('grade');
                grade=grade==null?0:grade;
        
                var major=GetQueryString('major');
                major=major==null?0:major;
        
                var classs=GetQueryString('class');
                classs=classs==null?0:classs;
        
                //var gender=GetQueryString('gender');
                //gender=gender==null?0:gender;
        
                //var page=GetQueryString('page');
                //page=page==null?0:page;
        
                var search=GetQueryString('search');
                search=search==null?'':search;

                url="./student-dormitory-exchanging.php?student_id="+student_id+"grade="+grade
                +"&major="+major+"&class="+classs+"&page="+$(this).val()+"&search="+search;
				window.location.href=url;
            break;
            default:break;
        }
    });
});